<!DOCTYPE html>
<html>
{include file='public/header'}
<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>标签名称
            </label>
            <div class="layui-input-inline">
                <input type="text" name="tag_name" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                增加
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //监听提交
        form.on('submit(add)', function (data) {
            //发异步，把数据提交给php
            $.post("{:url('add')}",data.field,function(response){
                if(response.code === 200){
                    layer.alert("增加成功", {icon: 6}, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        window.parent.location.reload();
                        //关闭当前frame
                        parent.layer.close(index);
                        return false;
                    });
                }else{
                    layer.msg(response.msg, {icon:5});
                    return false;
                }
            },'json')
            return false;
        });

    });
</script>
</body>
</html>